<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var constructMaximumBinaryTree = function (nums) {
      if (nums.length == 0) {
        return null
      }
      let maxNum = Math.max(...nums)
      let index = nums.indexOf(maxNum)
      return new TreeNode(
        maxNum,
        constructMaximumBinaryTree(nums.slice(0, index)),
        constructMaximumBinaryTree(nums.slice(index + 1))
      )
    };
    console.log(constructMaximumBinaryTree(nums = [3, 2, 1]))
  </script>
</body>

</html>